// import Home from '@/views/Home';
// import Search from '@/views/Search';
// import Login from '@/views/Login';
// import Register from '@/views/Register';
// import Detail from '@/views/Detail';
// import AddCartSuccess from '@/views/AddCartSuccess';
// import ShopCart from '@/views/ShopCart';
// import Center from '@/views/Center';
// import GroupOrder from '@/views/Center/GroupOrder'
// import MyOrder from '@/views/Center/MyOrder'
// import Trade from '@/views/Trade';
// import Pay from '@/views/Pay';
// import PaySuccess from '@/views/PaySuccess';
// 路由表是数组
export default [
  {
    path:'/home',
    component:() => import('@/views/Home'),//路由懒加载
  },
  {
    path:'/search/:keyword?',
    component:() => {return import('@/views/Search')},//retrun 很重要！！！！！！
    name:'search'
  },
  {
    path:'/detail/:skuId?',
    component:() => {return  import('@/views/Detail')},
  },
  //此组件不发网络请求
  {
    path:'/addcartsuccess',
    component:() => {return  import('@/views/AddCartSuccess')},
    beforeEnter: (to, from, next) => {
      let skuNum = to.query.skuNum;
      let skuInfo = sessionStorage.getItem('skuInfo_key');
      if (skuNum && skuInfo) {
        next()
      } else {
        next(false);//停在原地
      }
    }
  },
  {
    path:'/shopcart',
    component:() => {return  import('@/views/ShopCart')},
  },
  {
    path:'/login',
    component:() => {return  import('@/views/Login')},
    meta:{
      // 页脚组件是否隐藏
      isHidden:true
    }
  },
  {
    path:'/register',
    component:() => {return  import('@/views/Register')},
    meta:{
      // 页脚组件是否隐藏
      isHidden:true
    }
  },
  {
    path:'/center',
    component:() => {return  import('@/views/Center')},
    children:[
      {
        path:'myorder',
        component:() => {return  import('@/views/Center/MyOrder')},
      },
      {
        path:'grouporder',
        component:() => {return  import('@/views/Center/GroupOrder')},
      },
      {
        path:'',
        redirect:'myorder',
      }

    ]
  },
  {
    path:'/trade',
    component:() => {return  import('@/views/Trade')},
    beforeEnter: (to, from, next) => {
      if (from.path === '/shopcart') {
        next();
      } else {
        next(false);
      }
    }
  },
  {
    path:'/pay',
    component:() => {return  import('@/views/Pay')},
    beforeEnter: (to, from, next) => {
      if (from.path === '/trade') {
        next();
      } else {
        next(false);
      }
    }
  },
  {
    path:'/paysuccess',
    component:() => {return  import('@/views/PaySuccess')},
    beforeEnter: (to, from, next) => {
      if (from.path === '/pay') {
        next();
      } else {
        next(false);
      }
    }
  },
  {
    path:'/',
    // 重定向
    redirect:'/home'
  }
]